﻿#include "Packet.h"
#include "Enums.h"
#include "ClientPackets.h"
#include "ServerPackets.h"

namespace C = ClientPackets;
namespace S = ServerPackets;
bool Packet::IsServer = false;

Packet *Packet::ReceivePacket(std::vector<unsigned char> &rawBytes, std::vector<unsigned char> &extra)
{
    extra = rawBytes;

    Packet *p;

    if (rawBytes.size() < 4)
    {
        return nullptr; //| 2Bytes: Packet Size | 2Bytes: Packet ID |
    }

    int length = (rawBytes[1] << 8) + rawBytes[0];

    if (length > rawBytes.size() || length < 2)
    {
        return nullptr;
    }

//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (MemoryStream stream = new MemoryStream(rawBytes, 2, length - 2))
    {
        MemoryStream stream = MemoryStream(rawBytes, 2, length - 2);
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (BinaryReader reader = new BinaryReader(stream))
        {
        BinaryReader reader = BinaryReader(stream);
        try
        {
            short id = reader.ReadInt16();

            p = IsServer ? GetClientPacket(id) : GetServerPacket(id);
            if (p == nullptr)
            {
                return nullptr;
            }

            p->ReadPacket(reader);
        }
        catch (...)
        {
            return nullptr;
            //return new C.Disconnect();
        }
        }
    }

    extra = std::vector<unsigned char>(rawBytes.size() - length);
    Buffer::BlockCopy(rawBytes, length, extra, 0, rawBytes.size() - length);

    return p;
}

std::vector<unsigned char> Packet::GetPacketBytes()
{
    if (getIndex() < 0)
    {
        return std::vector<unsigned char>(0);
    }

    std::vector<unsigned char> data;

//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (MemoryStream stream = new MemoryStream())
    {
        MemoryStream stream = MemoryStream();
        stream.SetLength(2);
        stream.Seek(2, SeekOrigin::Begin);
//C# TO C++ CONVERTER NOTE: The following 'using' block is replaced by its C++ equivalent:
//ORIGINAL LINE: using (BinaryWriter writer = new BinaryWriter(stream))
        {
            BinaryWriter writer = BinaryWriter(stream);
            writer.Write(getIndex());
            WritePacket(writer);
            stream.Seek(0, SeekOrigin::Begin);
            writer.Write(static_cast<short>(stream.Length));
            stream.Seek(0, SeekOrigin::Begin);

            data = std::vector<unsigned char>(stream.Length);
            stream.Read(data, 0, data.size());
        }
    }

    return data;
}

Packet *Packet::GetClientPacket(short index)
{
    switch (index)
    {
        case static_cast<short>(ClientPacketIds::ClientVersion):
            return new C::ClientVersion();
        case static_cast<short>(ClientPacketIds::Disconnect):
            return new C::Disconnect();
        case static_cast<short>(ClientPacketIds::KeepAlive):
            return new C::KeepAlive();
        case static_cast<short>(ClientPacketIds::NewAccount):
            return new C::NewAccount();
        case static_cast<short>(ClientPacketIds::ChangePassword):
            return new C::ChangePassword();
        case static_cast<short>(ClientPacketIds::Login):
            return new C::Login();
        case static_cast<short>(ClientPacketIds::NewCharacter):
            return new C::NewCharacter();
        case static_cast<short>(ClientPacketIds::DeleteCharacter):
            return new C::DeleteCharacter();
        case static_cast<short>(ClientPacketIds::StartGame):
            return new C::StartGame();
        case static_cast<short>(ClientPacketIds::LogOut):
            return new C::LogOut();
        case static_cast<short>(ClientPacketIds::Turn):
            return new C::Turn();
        case static_cast<short>(ClientPacketIds::Walk):
            return new C::Walk();
        case static_cast<short>(ClientPacketIds::Run):
            return new C::Run();
        case static_cast<short>(ClientPacketIds::Chat):
            return new C::Chat();
        case static_cast<short>(ClientPacketIds::MoveItem):
            return new C::MoveItem();
        case static_cast<short>(ClientPacketIds::StoreItem):
            return new C::StoreItem();
        case static_cast<short>(ClientPacketIds::TakeBackItem):
            return new C::TakeBackItem();
        case static_cast<short>(ClientPacketIds::MergeItem):
            return new C::MergeItem();
        case static_cast<short>(ClientPacketIds::EquipItem):
            return new C::EquipItem();
        case static_cast<short>(ClientPacketIds::RemoveItem):
            return new C::RemoveItem();
        case static_cast<short>(ClientPacketIds::RemoveSlotItem):
            return new C::RemoveSlotItem();
        case static_cast<short>(ClientPacketIds::SplitItem):
            return new C::SplitItem();
        case static_cast<short>(ClientPacketIds::UseItem):
            return new C::UseItem();
        case static_cast<short>(ClientPacketIds::DropItem):
            return new C::DropItem();
        case static_cast<short>(ClientPacketIds::DepositRefineItem):
            return new C::DepositRefineItem();
        case static_cast<short>(ClientPacketIds::RetrieveRefineItem):
            return new C::RetrieveRefineItem();
        case static_cast<short>(ClientPacketIds::RefineCancel):
            return new C::RefineCancel();
        case static_cast<short>(ClientPacketIds::RefineItem):
            return new C::RefineItem();
        case static_cast<short>(ClientPacketIds::CheckRefine):
            return new C::CheckRefine();
        case static_cast<short>(ClientPacketIds::ReplaceWedRing):
            return new C::ReplaceWedRing();
        case static_cast<short>(ClientPacketIds::DepositTradeItem):
            return new C::DepositTradeItem();
        case static_cast<short>(ClientPacketIds::RetrieveTradeItem):
            return new C::RetrieveTradeItem();
        case static_cast<short>(ClientPacketIds::DropGold):
            return new C::DropGold();
        case static_cast<short>(ClientPacketIds::PickUp):
            return new C::PickUp();
        case static_cast<short>(ClientPacketIds::Inspect):
            return new C::Inspect();
        case static_cast<short>(ClientPacketIds::ChangeAMode):
            return new C::ChangeAMode();
        case static_cast<short>(ClientPacketIds::ChangePMode):
            return new C::ChangePMode();
        case static_cast<short>(ClientPacketIds::ChangeTrade):
            return new C::ChangeTrade();
        case static_cast<short>(ClientPacketIds::Attack):
            return new C::Attack();
        case static_cast<short>(ClientPacketIds::RangeAttack):
            return new C::RangeAttack();
        case static_cast<short>(ClientPacketIds::Harvest):
            return new C::Harvest();
        case static_cast<short>(ClientPacketIds::CallNPC):
            return new C::CallNPC();
        case static_cast<short>(ClientPacketIds::BuyItem):
            return new C::BuyItem();
        case static_cast<short>(ClientPacketIds::SellItem):
            return new C::SellItem();
        case static_cast<short>(ClientPacketIds::CraftItem):
            return new C::CraftItem();
        case static_cast<short>(ClientPacketIds::RepairItem):
            return new C::RepairItem();
        case static_cast<short>(ClientPacketIds::BuyItemBack):
            return new C::BuyItemBack();
        case static_cast<short>(ClientPacketIds::SRepairItem):
            return new C::SRepairItem();
        case static_cast<short>(ClientPacketIds::MagicKey):
            return new C::MagicKey();
        case static_cast<short>(ClientPacketIds::Magic):
            return new C::Magic();
        case static_cast<short>(ClientPacketIds::SwitchGroup):
            return new C::SwitchGroup();
        case static_cast<short>(ClientPacketIds::AddMember):
            return new C::AddMember();
        case static_cast<short>(ClientPacketIds::DellMember):
            return new C::DelMember();
        case static_cast<short>(ClientPacketIds::GroupInvite):
            return new C::GroupInvite();
        case static_cast<short>(ClientPacketIds::TownRevive):
            return new C::TownRevive();
        case static_cast<short>(ClientPacketIds::SpellToggle):
            return new C::SpellToggle();
        case static_cast<short>(ClientPacketIds::ConsignItem):
            return new C::ConsignItem();
        case static_cast<short>(ClientPacketIds::MarketSearch):
            return new C::MarketSearch();
        case static_cast<short>(ClientPacketIds::MarketRefresh):
            return new C::MarketRefresh();
        case static_cast<short>(ClientPacketIds::MarketPage):
            return new C::MarketPage();
        case static_cast<short>(ClientPacketIds::MarketBuy):
            return new C::MarketBuy();
        case static_cast<short>(ClientPacketIds::MarketGetBack):
            return new C::MarketGetBack();
        case static_cast<short>(ClientPacketIds::MarketSellNow):
            return new C::MarketSellNow();
        case static_cast<short>(ClientPacketIds::RequestUserName):
            return new C::RequestUserName();
        case static_cast<short>(ClientPacketIds::RequestChatItem):
            return new C::RequestChatItem();
        case static_cast<short>(ClientPacketIds::EditGuildMember):
            return new C::EditGuildMember();
        case static_cast<short>(ClientPacketIds::EditGuildNotice):
            return new C::EditGuildNotice();
        case static_cast<short>(ClientPacketIds::GuildInvite):
            return new C::GuildInvite();
        case static_cast<short>(ClientPacketIds::GuildNameReturn):
            return new C::GuildNameReturn();
        case static_cast<short>(ClientPacketIds::RequestGuildInfo):
            return new C::RequestGuildInfo();
        case static_cast<short>(ClientPacketIds::GuildStorageGoldChange):
            return new C::GuildStorageGoldChange();
        case static_cast<short>(ClientPacketIds::GuildStorageItemChange):
            return new C::GuildStorageItemChange();
        case static_cast<short>(ClientPacketIds::GuildWarReturn):
            return new C::GuildWarReturn();
        case static_cast<short>(ClientPacketIds::MarriageRequest):
            return new C::MarriageRequest();
        case static_cast<short>(ClientPacketIds::MarriageReply):
            return new C::MarriageReply();
        case static_cast<short>(ClientPacketIds::ChangeMarriage):
            return new C::ChangeMarriage();
        case static_cast<short>(ClientPacketIds::DivorceRequest):
            return new C::DivorceRequest();
        case static_cast<short>(ClientPacketIds::DivorceReply):
            return new C::DivorceReply();
        case static_cast<short>(ClientPacketIds::AddMentor):
            return new C::AddMentor();
        case static_cast<short>(ClientPacketIds::MentorReply):
            return new C::MentorReply();
        case static_cast<short>(ClientPacketIds::AllowMentor):
            return new C::AllowMentor();
        case static_cast<short>(ClientPacketIds::CancelMentor):
            return new C::CancelMentor();
        case static_cast<short>(ClientPacketIds::TradeRequest):
            return new C::TradeRequest();
        case static_cast<short>(ClientPacketIds::TradeReply):
            return new C::TradeReply();
        case static_cast<short>(ClientPacketIds::TradeGold):
            return new C::TradeGold();
        case static_cast<short>(ClientPacketIds::TradeConfirm):
            return new C::TradeConfirm();
        case static_cast<short>(ClientPacketIds::TradeCancel):
            return new C::TradeCancel();
        case static_cast<short>(ClientPacketIds::EquipSlotItem):
            return new C::EquipSlotItem();
        case static_cast<short>(ClientPacketIds::FishingCast):
            return new C::FishingCast();
        case static_cast<short>(ClientPacketIds::FishingChangeAutocast):
            return new C::FishingChangeAutocast();
        case static_cast<short>(ClientPacketIds::AcceptQuest):
            return new C::AcceptQuest();
        case static_cast<short>(ClientPacketIds::FinishQuest):
            return new C::FinishQuest();
        case static_cast<short>(ClientPacketIds::AbandonQuest):
            return new C::AbandonQuest();
        case static_cast<short>(ClientPacketIds::ShareQuest):
            return new C::ShareQuest();
        case static_cast<short>(ClientPacketIds::AcceptReincarnation):
            return new C::AcceptReincarnation();
        case static_cast<short>(ClientPacketIds::CancelReincarnation):
            return new C::CancelReincarnation();
        case static_cast<short>(ClientPacketIds::CombineItem):
            return new C::CombineItem();
        case static_cast<short>(ClientPacketIds::AwakeningNeedMaterials):
            return new C::AwakeningNeedMaterials();
        case static_cast<short>(ClientPacketIds::AwakeningLockedItem):
            return new C::AwakeningLockedItem();
        case static_cast<short>(ClientPacketIds::Awakening):
            return new C::Awakening();
        case static_cast<short>(ClientPacketIds::DisassembleItem):
            return new C::DisassembleItem();
        case static_cast<short>(ClientPacketIds::DowngradeAwakening):
            return new C::DowngradeAwakening();
        case static_cast<short>(ClientPacketIds::ResetAddedItem):
            return new C::ResetAddedItem();
        case static_cast<short>(ClientPacketIds::SendMail):
            return new C::SendMail();
        case static_cast<short>(ClientPacketIds::ReadMail):
            return new C::ReadMail();
        case static_cast<short>(ClientPacketIds::CollectParcel):
            return new C::CollectParcel();
        case static_cast<short>(ClientPacketIds::DeleteMail):
            return new C::DeleteMail();
        case static_cast<short>(ClientPacketIds::LockMail):
            return new C::LockMail();
        case static_cast<short>(ClientPacketIds::MailLockedItem):
            return new C::MailLockedItem();
        case static_cast<short>(ClientPacketIds::MailCost):
            return new C::MailCost();
        case static_cast<short>(ClientPacketIds::RequestIntelligentCreatureUpdates):
            return new C::RequestIntelligentCreatureUpdates();
        case static_cast<short>(ClientPacketIds::UpdateIntelligentCreature):
            return new C::UpdateIntelligentCreature();
        case static_cast<short>(ClientPacketIds::IntelligentCreaturePickup):
            return new C::IntelligentCreaturePickup();
        case static_cast<short>(ClientPacketIds::AddFriend):
            return new C::AddFriend();
        case static_cast<short>(ClientPacketIds::RemoveFriend):
            return new C::RemoveFriend();
        case static_cast<short>(ClientPacketIds::RefreshFriends):
            return new C::RefreshFriends();
        case static_cast<short>(ClientPacketIds::AddMemo):
            return new C::AddMemo();
        case static_cast<short>(ClientPacketIds::GuildBuffUpdate):
            return new C::GuildBuffUpdate();
        case static_cast<short>(ClientPacketIds::GameshopBuy):
            return new C::GameshopBuy();
        case static_cast<short>(ClientPacketIds::NPCConfirmInput):
            return new C::NPCConfirmInput();
        case static_cast<short>(ClientPacketIds::ReportIssue):
            return new C::ReportIssue();
        case static_cast<short>(ClientPacketIds::GetRanking):
            return new C::GetRanking();
        case static_cast<short>(ClientPacketIds::Opendoor):
            return new C::Opendoor();
        case static_cast<short>(ClientPacketIds::GetRentedItems):
            return new C::GetRentedItems();
        case static_cast<short>(ClientPacketIds::ItemRentalRequest):
            return new C::ItemRentalRequest();
        case static_cast<short>(ClientPacketIds::ItemRentalFee):
            return new C::ItemRentalFee();
        case static_cast<short>(ClientPacketIds::ItemRentalPeriod):
            return new C::ItemRentalPeriod();
        case static_cast<short>(ClientPacketIds::DepositRentalItem):
            return new C::DepositRentalItem();
        case static_cast<short>(ClientPacketIds::RetrieveRentalItem):
            return new C::RetrieveRentalItem();
        case static_cast<short>(ClientPacketIds::CancelItemRental):
            return new C::CancelItemRental();
        case static_cast<short>(ClientPacketIds::ItemRentalLockFee):
            return new C::ItemRentalLockFee();
        case static_cast<short>(ClientPacketIds::ItemRentalLockItem):
            return new C::ItemRentalLockItem();
        case static_cast<short>(ClientPacketIds::ConfirmItemRental):
            return new C::ConfirmItemRental();
        default:
            return nullptr;
    }

}

Packet *Packet::GetServerPacket(short index)
{
    switch (index)
    {
        case static_cast<short>(ServerPacketIds::Connected):
            return new S::Connected();
        case static_cast<short>(ServerPacketIds::ClientVersion):
            return new S::ClientVersion();
        case static_cast<short>(ServerPacketIds::Disconnect):
            return new S::Disconnect();
        case static_cast<short>(ServerPacketIds::KeepAlive):
            return new S::KeepAlive();
        case static_cast<short>(ServerPacketIds::NewAccount):
            return new S::NewAccount();
        case static_cast<short>(ServerPacketIds::ChangePassword):
            return new S::ChangePassword();
        case static_cast<short>(ServerPacketIds::ChangePasswordBanned):
            return new S::ChangePasswordBanned();
        case static_cast<short>(ServerPacketIds::Login):
            return new S::Login();
        case static_cast<short>(ServerPacketIds::LoginBanned):
            return new S::LoginBanned();
        case static_cast<short>(ServerPacketIds::LoginSuccess):
            return new S::LoginSuccess();
        case static_cast<short>(ServerPacketIds::NewCharacter):
            return new S::NewCharacter();
        case static_cast<short>(ServerPacketIds::NewCharacterSuccess):
            return new S::NewCharacterSuccess();
        case static_cast<short>(ServerPacketIds::DeleteCharacter):
            return new S::DeleteCharacter();
        case static_cast<short>(ServerPacketIds::DeleteCharacterSuccess):
            return new S::DeleteCharacterSuccess();
        case static_cast<short>(ServerPacketIds::StartGame):
            return new S::StartGame();
        case static_cast<short>(ServerPacketIds::StartGameBanned):
            return new S::StartGameBanned();
        case static_cast<short>(ServerPacketIds::StartGameDelay):
            return new S::StartGameDelay();
        case static_cast<short>(ServerPacketIds::MapInformation):
            return new S::MapInformation();
        case static_cast<short>(ServerPacketIds::UserInformation):
            return new S::UserInformation();
        case static_cast<short>(ServerPacketIds::UserSlotsRefresh):
            return new S::UserSlotsRefresh();
        case static_cast<short>(ServerPacketIds::UserLocation):
            return new S::UserLocation();
        case static_cast<short>(ServerPacketIds::ObjectPlayer):
            return new S::ObjectPlayer();
        case static_cast<short>(ServerPacketIds::ObjectRemove):
            return new S::ObjectRemove();
        case static_cast<short>(ServerPacketIds::ObjectTurn):
            return new S::ObjectTurn();
        case static_cast<short>(ServerPacketIds::ObjectWalk):
            return new S::ObjectWalk();
        case static_cast<short>(ServerPacketIds::ObjectRun):
            return new S::ObjectRun();
        case static_cast<short>(ServerPacketIds::Chat):
            return new S::Chat();
        case static_cast<short>(ServerPacketIds::ObjectChat):
            return new S::ObjectChat();
        case static_cast<short>(ServerPacketIds::NewItemInfo):
            return new S::NewItemInfo();
        case static_cast<short>(ServerPacketIds::NewChatItem):
            return new S::NewChatItem();
        case static_cast<short>(ServerPacketIds::MoveItem):
            return new S::MoveItem();
        case static_cast<short>(ServerPacketIds::EquipItem):
            return new S::EquipItem();
        case static_cast<short>(ServerPacketIds::MergeItem):
            return new S::MergeItem();
        case static_cast<short>(ServerPacketIds::RemoveItem):
            return new S::RemoveItem();
        case static_cast<short>(ServerPacketIds::RemoveSlotItem):
            return new S::RemoveSlotItem();
        case static_cast<short>(ServerPacketIds::TakeBackItem):
            return new S::TakeBackItem();
        case static_cast<short>(ServerPacketIds::StoreItem):
            return new S::StoreItem();
        case static_cast<short>(ServerPacketIds::DepositRefineItem):
            return new S::DepositRefineItem();
        case static_cast<short>(ServerPacketIds::RetrieveRefineItem):
            return new S::RetrieveRefineItem();
        case static_cast<short>(ServerPacketIds::RefineItem):
            return new S::RefineItem();
        case static_cast<short>(ServerPacketIds::DepositTradeItem):
            return new S::DepositTradeItem();
        case static_cast<short>(ServerPacketIds::RetrieveTradeItem):
            return new S::RetrieveTradeItem();
        case static_cast<short>(ServerPacketIds::SplitItem):
            return new S::SplitItem();
        case static_cast<short>(ServerPacketIds::SplitItem1):
            return new S::SplitItem1();
        case static_cast<short>(ServerPacketIds::UseItem):
            return new S::UseItem();
        case static_cast<short>(ServerPacketIds::DropItem):
            return new S::DropItem();
        case static_cast<short>(ServerPacketIds::PlayerUpdate):
            return new S::PlayerUpdate();
        case static_cast<short>(ServerPacketIds::PlayerInspect):
            return new S::PlayerInspect();
        case static_cast<short>(ServerPacketIds::LogOutSuccess):
            return new S::LogOutSuccess();
        case static_cast<short>(ServerPacketIds::LogOutFailed):
            return new S::LogOutFailed();
        case static_cast<short>(ServerPacketIds::TimeOfDay):
            return new S::TimeOfDay();
        case static_cast<short>(ServerPacketIds::ChangeAMode):
            return new S::ChangeAMode();
        case static_cast<short>(ServerPacketIds::ChangePMode):
            return new S::ChangePMode();
        case static_cast<short>(ServerPacketIds::ObjectItem):
            return new S::ObjectItem();
        case static_cast<short>(ServerPacketIds::ObjectGold):
            return new S::ObjectGold();
        case static_cast<short>(ServerPacketIds::GainedItem):
            return new S::GainedItem();
        case static_cast<short>(ServerPacketIds::GainedGold):
            return new S::GainedGold();
        case static_cast<short>(ServerPacketIds::LoseGold):
            return new S::LoseGold();
        case static_cast<short>(ServerPacketIds::GainedCredit):
            return new S::GainedCredit();
        case static_cast<short>(ServerPacketIds::LoseCredit):
            return new S::LoseCredit();
        case static_cast<short>(ServerPacketIds::ObjectMonster):
            return new S::ObjectMonster();
        case static_cast<short>(ServerPacketIds::ObjectAttack):
            return new S::ObjectAttack();
        case static_cast<short>(ServerPacketIds::Struck):
            return new S::Struck();
        case static_cast<short>(ServerPacketIds::DamageIndicator):
            return new S::DamageIndicator();
        case static_cast<short>(ServerPacketIds::ObjectStruck):
            return new S::ObjectStruck();
        case static_cast<short>(ServerPacketIds::DuraChanged):
            return new S::DuraChanged();
        case static_cast<short>(ServerPacketIds::HealthChanged):
            return new S::HealthChanged();
        case static_cast<short>(ServerPacketIds::DeleteItem):
            return new S::DeleteItem();
        case static_cast<short>(ServerPacketIds::Death):
            return new S::Death();
        case static_cast<short>(ServerPacketIds::ObjectDied):
            return new S::ObjectDied();
        case static_cast<short>(ServerPacketIds::ColourChanged):
            return new S::ColourChanged();
        case static_cast<short>(ServerPacketIds::ObjectColourChanged):
            return new S::ObjectColourChanged();
        case static_cast<short>(ServerPacketIds::ObjectGuildNameChanged):
            return new S::ObjectGuildNameChanged();
        case static_cast<short>(ServerPacketIds::GainExperience):
            return new S::GainExperience();
        case static_cast<short>(ServerPacketIds::LevelChanged):
            return new S::LevelChanged();
        case static_cast<short>(ServerPacketIds::ObjectLeveled):
            return new S::ObjectLeveled();
        case static_cast<short>(ServerPacketIds::ObjectHarvest):
            return new S::ObjectHarvest();
        case static_cast<short>(ServerPacketIds::ObjectHarvested):
            return new S::ObjectHarvested();
        case static_cast<short>(ServerPacketIds::ObjectNpc):
            return new S::ObjectNPC();
        case static_cast<short>(ServerPacketIds::NPCResponse):
            return new S::NPCResponse();
        case static_cast<short>(ServerPacketIds::ObjectHide):
            return new S::ObjectHide();
        case static_cast<short>(ServerPacketIds::ObjectShow):
            return new S::ObjectShow();
        case static_cast<short>(ServerPacketIds::Poisoned):
            return new S::Poisoned();
        case static_cast<short>(ServerPacketIds::ObjectPoisoned):
            return new S::ObjectPoisoned();
        case static_cast<short>(ServerPacketIds::MapChanged):
            return new S::MapChanged();
        case static_cast<short>(ServerPacketIds::ObjectTeleportOut):
            return new S::ObjectTeleportOut();
        case static_cast<short>(ServerPacketIds::ObjectTeleportIn):
            return new S::ObjectTeleportIn();
        case static_cast<short>(ServerPacketIds::TeleportIn):
            return new S::TeleportIn();
        case static_cast<short>(ServerPacketIds::NPCGoods):
            return new S::NPCGoods();
        case static_cast<short>(ServerPacketIds::NPCSell):
            return new S::NPCSell();
        case static_cast<short>(ServerPacketIds::NPCRepair):
            return new S::NPCRepair();
        case static_cast<short>(ServerPacketIds::NPCSRepair):
            return new S::NPCSRepair();
        case static_cast<short>(ServerPacketIds::NPCRefine):
            return new S::NPCRefine();
        case static_cast<short>(ServerPacketIds::NPCCheckRefine):
            return new S::NPCCheckRefine();
        case static_cast<short>(ServerPacketIds::NPCCollectRefine):
            return new S::NPCCollectRefine();
        case static_cast<short>(ServerPacketIds::NPCReplaceWedRing):
            return new S::NPCReplaceWedRing();
        case static_cast<short>(ServerPacketIds::NPCStorage):
            return new S::NPCStorage();
        case static_cast<short>(ServerPacketIds::SellItem):
            return new S::SellItem();
        case static_cast<short>(ServerPacketIds::CraftItem):
            return new S::CraftItem();
        case static_cast<short>(ServerPacketIds::RepairItem):
            return new S::RepairItem();
        case static_cast<short>(ServerPacketIds::ItemRepaired):
            return new S::ItemRepaired();
        case static_cast<short>(ServerPacketIds::ItemSlotSizeChanged):
            return new S::ItemSlotSizeChanged();
        case static_cast<short>(ServerPacketIds::NewMagic):
            return new S::NewMagic();
        case static_cast<short>(ServerPacketIds::MagicLeveled):
            return new S::MagicLeveled();
        case static_cast<short>(ServerPacketIds::Magic):
            return new S::Magic();
        case static_cast<short>(ServerPacketIds::MagicDelay):
            return new S::MagicDelay();
        case static_cast<short>(ServerPacketIds::MagicCast):
            return new S::MagicCast();
        case static_cast<short>(ServerPacketIds::ObjectMagic):
            return new S::ObjectMagic();
        case static_cast<short>(ServerPacketIds::ObjectProjectile):
            return new S::ObjectProjectile();
        case static_cast<short>(ServerPacketIds::ObjectEffect):
            return new S::ObjectEffect();
        case static_cast<short>(ServerPacketIds::RangeAttack):
            return new S::RangeAttack();
        case static_cast<short>(ServerPacketIds::Pushed):
            return new S::Pushed();
        case static_cast<short>(ServerPacketIds::ObjectPushed):
            return new S::ObjectPushed();
        case static_cast<short>(ServerPacketIds::ObjectName):
            return new S::ObjectName();
        case static_cast<short>(ServerPacketIds::UserStorage):
            return new S::UserStorage();
        case static_cast<short>(ServerPacketIds::SwitchGroup):
            return new S::SwitchGroup();
        case static_cast<short>(ServerPacketIds::DeleteGroup):
            return new S::DeleteGroup();
        case static_cast<short>(ServerPacketIds::DeleteMember):
            return new S::DeleteMember();
        case static_cast<short>(ServerPacketIds::GroupInvite):
            return new S::GroupInvite();
        case static_cast<short>(ServerPacketIds::AddMember):
            return new S::AddMember();
        case static_cast<short>(ServerPacketIds::Revived):
            return new S::Revived();
        case static_cast<short>(ServerPacketIds::ObjectRevived):
            return new S::ObjectRevived();
        case static_cast<short>(ServerPacketIds::SpellToggle):
            return new S::SpellToggle();
        case static_cast<short>(ServerPacketIds::ObjectHealth):
            return new S::ObjectHealth();
        case static_cast<short>(ServerPacketIds::MapEffect):
            return new S::MapEffect();
        case static_cast<short>(ServerPacketIds::ObjectRangeAttack):
            return new S::ObjectRangeAttack();
        case static_cast<short>(ServerPacketIds::AddBuff):
            return new S::AddBuff();
        case static_cast<short>(ServerPacketIds::RemoveBuff):
            return new S::RemoveBuff();
        case static_cast<short>(ServerPacketIds::ObjectHidden):
            return new S::ObjectHidden();
        case static_cast<short>(ServerPacketIds::RefreshItem):
            return new S::RefreshItem();
        case static_cast<short>(ServerPacketIds::ObjectSpell):
            return new S::ObjectSpell();
        case static_cast<short>(ServerPacketIds::UserDash):
            return new S::UserDash();
        case static_cast<short>(ServerPacketIds::ObjectDash):
            return new S::ObjectDash();
        case static_cast<short>(ServerPacketIds::UserDashFail):
            return new S::UserDashFail();
        case static_cast<short>(ServerPacketIds::ObjectDashFail):
            return new S::ObjectDashFail();
        case static_cast<short>(ServerPacketIds::NPCConsign):
            return new S::NPCConsign();
        case static_cast<short>(ServerPacketIds::NPCMarket):
            return new S::NPCMarket();
        case static_cast<short>(ServerPacketIds::NPCMarketPage):
            return new S::NPCMarketPage();
        case static_cast<short>(ServerPacketIds::ConsignItem):
            return new S::ConsignItem();
        case static_cast<short>(ServerPacketIds::MarketFail):
            return new S::MarketFail();
        case static_cast<short>(ServerPacketIds::MarketSuccess):
            return new S::MarketSuccess();
        case static_cast<short>(ServerPacketIds::ObjectSitDown):
            return new S::ObjectSitDown();
        case static_cast<short>(ServerPacketIds::InTrapRock):
            return new S::InTrapRock();
        case static_cast<short>(ServerPacketIds::RemoveMagic):
            return new S::RemoveMagic();
        case static_cast<short>(ServerPacketIds::BaseStatsInfo):
            return new S::BaseStatsInfo();
        case static_cast<short>(ServerPacketIds::UserName):
            return new S::UserName();
        case static_cast<short>(ServerPacketIds::ChatItemStats):
            return new S::ChatItemStats();
        case static_cast<short>(ServerPacketIds::GuildMemberChange):
            return new S::GuildMemberChange();
        case static_cast<short>(ServerPacketIds::GuildNoticeChange):
            return new S::GuildNoticeChange();
        case static_cast<short>(ServerPacketIds::GuildStatus):
            return new S::GuildStatus();
        case static_cast<short>(ServerPacketIds::GuildInvite):
            return new S::GuildInvite();
        case static_cast<short>(ServerPacketIds::GuildExpGain):
            return new S::GuildExpGain();
        case static_cast<short>(ServerPacketIds::GuildNameRequest):
            return new S::GuildNameRequest();
        case static_cast<short>(ServerPacketIds::GuildStorageGoldChange):
            return new S::GuildStorageGoldChange();
        case static_cast<short>(ServerPacketIds::GuildStorageItemChange):
            return new S::GuildStorageItemChange();
        case static_cast<short>(ServerPacketIds::GuildStorageList):
            return new S::GuildStorageList();
        case static_cast<short>(ServerPacketIds::GuildRequestWar):
            return new S::GuildRequestWar();
        case static_cast<short>(ServerPacketIds::DefaultNPC):
            return new S::DefaultNPC();
        case static_cast<short>(ServerPacketIds::NPCUpdate):
            return new S::NPCUpdate();
        case static_cast<short>(ServerPacketIds::NPCImageUpdate):
            return new S::NPCImageUpdate();
        case static_cast<short>(ServerPacketIds::MarriageRequest):
            return new S::MarriageRequest();
        case static_cast<short>(ServerPacketIds::DivorceRequest):
            return new S::DivorceRequest();
        case static_cast<short>(ServerPacketIds::MentorRequest):
            return new S::MentorRequest();
        case static_cast<short>(ServerPacketIds::TradeRequest):
            return new S::TradeRequest();
        case static_cast<short>(ServerPacketIds::TradeAccept):
            return new S::TradeAccept();
        case static_cast<short>(ServerPacketIds::TradeGold):
            return new S::TradeGold();
        case static_cast<short>(ServerPacketIds::TradeItem):
            return new S::TradeItem();
        case static_cast<short>(ServerPacketIds::TradeConfirm):
            return new S::TradeConfirm();
        case static_cast<short>(ServerPacketIds::TradeCancel):
            return new S::TradeCancel();
        case static_cast<short>(ServerPacketIds::MountUpdate):
            return new S::MountUpdate();
        case static_cast<short>(ServerPacketIds::TransformUpdate):
            return new S::TransformUpdate();
        case static_cast<short>(ServerPacketIds::EquipSlotItem):
            return new S::EquipSlotItem();
        case static_cast<short>(ServerPacketIds::FishingUpdate):
            return new S::FishingUpdate();
        case static_cast<short>(ServerPacketIds::ChangeQuest):
            return new S::ChangeQuest();
        case static_cast<short>(ServerPacketIds::CompleteQuest):
            return new S::CompleteQuest();
        case static_cast<short>(ServerPacketIds::ShareQuest):
            return new S::ShareQuest();
        case static_cast<short>(ServerPacketIds::NewQuestInfo):
            return new S::NewQuestInfo();
        case static_cast<short>(ServerPacketIds::GainedQuestItem):
            return new S::GainedQuestItem();
        case static_cast<short>(ServerPacketIds::DeleteQuestItem):
            return new S::DeleteQuestItem();
        case static_cast<short>(ServerPacketIds::CancelReincarnation):
            return new S::CancelReincarnation();
        case static_cast<short>(ServerPacketIds::RequestReincarnation):
            return new S::RequestReincarnation();
        case static_cast<short>(ServerPacketIds::UserBackStep):
            return new S::UserBackStep();
        case static_cast<short>(ServerPacketIds::ObjectBackStep):
            return new S::ObjectBackStep();
        case static_cast<short>(ServerPacketIds::UserDashAttack):
            return new S::UserDashAttack();
        case static_cast<short>(ServerPacketIds::ObjectDashAttack):
            return new S::ObjectDashAttack();
        case static_cast<short>(ServerPacketIds::UserAttackMove): //Warrior Skill - SlashingBurst
            return new S::UserAttackMove();
        case static_cast<short>(ServerPacketIds::CombineItem):
            return new S::CombineItem();
        case static_cast<short>(ServerPacketIds::ItemUpgraded):
            return new S::ItemUpgraded();
        case static_cast<short>(ServerPacketIds::SetConcentration):
            return new S::SetConcentration();
        case static_cast<short>(ServerPacketIds::SetElemental):
            return new S::SetElemental();
        case static_cast<short>(ServerPacketIds::RemoveDelayedExplosion):
            return new S::RemoveDelayedExplosion();
        case static_cast<short>(ServerPacketIds::ObjectDeco):
            return new S::ObjectDeco();
        case static_cast<short>(ServerPacketIds::ObjectSneaking):
            return new S::ObjectSneaking();
        case static_cast<short>(ServerPacketIds::ObjectLevelEffects):
            return new S::ObjectLevelEffects();
        case static_cast<short>(ServerPacketIds::SetBindingShot):
            return new S::SetBindingShot();
        case static_cast<short>(ServerPacketIds::SendOutputMessage):
            return new S::SendOutputMessage();
        case static_cast<short>(ServerPacketIds::NPCAwakening):
            return new S::NPCAwakening();
        case static_cast<short>(ServerPacketIds::NPCDisassemble):
            return new S::NPCDisassemble();
        case static_cast<short>(ServerPacketIds::NPCDowngrade):
            return new S::NPCDowngrade();
        case static_cast<short>(ServerPacketIds::NPCReset):
            return new S::NPCReset();
        case static_cast<short>(ServerPacketIds::AwakeningNeedMaterials):
            return new S::AwakeningNeedMaterials();
        case static_cast<short>(ServerPacketIds::AwakeningLockedItem):
            return new S::AwakeningLockedItem();
        case static_cast<short>(ServerPacketIds::Awakening):
            return new S::Awakening();
        case static_cast<short>(ServerPacketIds::ReceiveMail):
            return new S::ReceiveMail();
        case static_cast<short>(ServerPacketIds::MailLockedItem):
            return new S::MailLockedItem();
        case static_cast<short>(ServerPacketIds::MailSent):
            return new S::MailSent();
        case static_cast<short>(ServerPacketIds::MailSendRequest):
            return new S::MailSendRequest();
        case static_cast<short>(ServerPacketIds::ParcelCollected):
            return new S::ParcelCollected();
        case static_cast<short>(ServerPacketIds::MailCost):
            return new S::MailCost();
        case static_cast<short>(ServerPacketIds::ResizeInventory):
            return new S::ResizeInventory();
        case static_cast<short>(ServerPacketIds::ResizeStorage):
            return new S::ResizeStorage();
        case static_cast<short>(ServerPacketIds::NewIntelligentCreature):
            return new S::NewIntelligentCreature();
        case static_cast<short>(ServerPacketIds::UpdateIntelligentCreatureList):
            return new S::UpdateIntelligentCreatureList();
        case static_cast<short>(ServerPacketIds::IntelligentCreatureEnableRename):
            return new S::IntelligentCreatureEnableRename();
        case static_cast<short>(ServerPacketIds::IntelligentCreaturePickup):
            return new S::IntelligentCreaturePickup();
        case static_cast<short>(ServerPacketIds::NPCPearlGoods):
            return new S::NPCPearlGoods();
        case static_cast<short>(ServerPacketIds::FriendUpdate):
            return new S::FriendUpdate();
        case static_cast<short>(ServerPacketIds::LoverUpdate):
            return new S::LoverUpdate();
        case static_cast<short>(ServerPacketIds::MentorUpdate):
            return new S::MentorUpdate();
        case static_cast<short>(ServerPacketIds::GuildBuffList):
            return new S::GuildBuffList();
        case static_cast<short>(ServerPacketIds::GameShopInfo):
            return new S::GameShopInfo();
        case static_cast<short>(ServerPacketIds::GameShopStock):
            return new S::GameShopStock();
        case static_cast<short>(ServerPacketIds::NPCRequestInput):
            return new S::NPCRequestInput();
        case static_cast<short>(ServerPacketIds::Rankings):
            return new S::Rankings();
        case static_cast<short>(ServerPacketIds::Opendoor):
            return new S::Opendoor();
        case static_cast<short>(ServerPacketIds::GetRentedItems):
            return new S::GetRentedItems();
        case static_cast<short>(ServerPacketIds::ItemRentalRequest):
            return new S::ItemRentalRequest();
        case static_cast<short>(ServerPacketIds::ItemRentalFee):
            return new S::ItemRentalFee();
        case static_cast<short>(ServerPacketIds::ItemRentalPeriod):
            return new S::ItemRentalPeriod();
        case static_cast<short>(ServerPacketIds::DepositRentalItem):
            return new S::DepositRentalItem();
        case static_cast<short>(ServerPacketIds::RetrieveRentalItem):
            return new S::RetrieveRentalItem();
        case static_cast<short>(ServerPacketIds::UpdateRentalItem):
            return new S::UpdateRentalItem();
        case static_cast<short>(ServerPacketIds::CancelItemRental):
            return new S::CancelItemRental();
        case static_cast<short>(ServerPacketIds::ItemRentalLock):
            return new S::ItemRentalLock();
        case static_cast<short>(ServerPacketIds::ItemRentalPartnerLock):
            return new S::ItemRentalPartnerLock();
        case static_cast<short>(ServerPacketIds::CanConfirmItemRental):
            return new S::CanConfirmItemRental();
        case static_cast<short>(ServerPacketIds::ConfirmItemRental):
            return new S::ConfirmItemRental();
        case static_cast<short>(ServerPacketIds::NewRecipeInfo):
            return new S::NewRecipeInfo();
        case static_cast<short>(ServerPacketIds::OpenBrowser):
            return new S::OpenBrowser();
        case static_cast<short>(ServerPacketIds::PlaySound):
            return new S::PlaySound();
        case static_cast<short>(ServerPacketIds::SetTimer):
            return new S::SetTimer();
        case static_cast<short>(ServerPacketIds::ExpireTimer):
            return new S::ExpireTimer();
        case static_cast<short>(ServerPacketIds::UpdateNotice):
            return new S::UpdateNotice();
        default:
            return nullptr;
    }
}
